package cn.finder.estimote;

import android.app.Activity;
import android.content.Context;

import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;

public class FinderBeaconManager {

	private BeaconManager beaconManager;
	
	private Context context;
	
	private Region region;
	
	public FinderBeaconManager(Context context,Region region){
		
		this.context=context;
		this.region=region;
		beaconManager=new BeaconManager(context);
		
	}
	
	public BeaconManager getBeaconManager(){
		return this.beaconManager;
	}
	
	/***
	 * 开始扫描beacon设备
	 * @param region
	 */
	public void startScanning(){
		beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
			
			public void onServiceReady() {
				beaconManager.startRanging(region);
			}
		});
	}
	
	
	public void disconnect(){
		beaconManager.disconnect();
	}
	
	public void resume(){
		if (SystemRequirementsChecker.checkWithDefaultDialogs((Activity)context)) {
            startScanning();
        }
	}
	
	
	public void stop(){
		 beaconManager.stopRanging(region);
	}
	
}
